// pages/focus_packets/focus_packets.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    gongzhonghao: {},
    kefu: {},
    guanzhugongzhonghao: false,
    guanzhukefu: false
  },
  receive: function() {

  },
  todetails: function() {
    var vm = this
    if (vm.data.guanzhukefu) {
      wx.navigateTo({
        url: '/pages/webview/webview?url=' + vm.data.kefu.location + "&title=" + "客服",
      })
    } else {
      vm.getBenfit("1")
    }
  },
  todetails2: function() {
    var vm = this
    if (vm.data.guanzhugongzhonghao) {
      wx.navigateTo({
        url: '/pages/webview/webview?url=' + vm.data.gongzhonghao.location + "&title=天天必听公众号",
      })
    } else {
      vm.getBenfit("0")
    }
  },


  //获取关注
  getBenfit: function(type) {
    // 0  公众号   1 客服
    var vm = this
    var data = {
      "userId": wx.getStorageSync("userId"),
      "type": type
    }
    getApp().request(getApp().globalData.https + "orderResource/followWeiXinNo",
      "get", data,
      function(res) {
        if (res.code == 0) {
          // vm.getuserinfo();
          if (type == "0") {
            wx.navigateTo({
              url: '/pages/webview/webview?url=' + vm.data.gongzhonghao.location + "&title=天天必听公众号",
            })
          } else {
            wx.navigateTo({
              url: '/pages/webview/webview?url=' + vm.data.kefu.location + "&title=" + "客服",
            })
          }
        }
      },
      function(res) {});
  },
  //获取关注天天必听公账号h5地址
  getGongzhonghao: function() {
    var vm = this
    getApp().request(getApp().globalData.https + "resourcesResource/markOfficialAccount",
      "get", '',
      function(res) {
        if (res.code == 0) {
          vm.setData({
            gongzhonghao: res.data
          })
        }
      },
      function(res) {});
  },

  //获取关注天天必听公账号h5地址
  getuserinfo: function() {
    var vm = this
    var data = {
      userId: wx.getStorageSync("userId")
    }
    getApp().requestLoading(getApp().globalData.https + "userResource/userDetailInfo",
      "get", data, "加载中..",
      function(res) {
        if (res.code == 0) {
          vm.setData({
            guanzhugongzhonghao: res.data.followOfficialNum == "1",
            guanzhukefu: res.data.followWXNum == "1"
          })
        }
      },
      function(res) {});
  },

  //获取关注客服小姐姐h5地址
  getkefu: function() {
    var vm = this
    getApp().request(getApp().globalData.https + "resourcesResource/markWaiterH5",
      "get", '',
      function(res) {
        if (res.code == 0) {
          vm.setData({
            kefu: res.data
          })
        }
      },
      function(res) {});
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getkefu();
    this.getGongzhonghao();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getuserinfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})